﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace JsGame
{
    public enum JsVarType
        {
           boolean,
           uint16,
           int16,
           str,
           js_list,
           js_pic,
           js_pos,
           js_talk,
           js_task,
           js_npc,
           js_item,
           js_skill,
           js_shop,
           js_suit,
           js_scene,
           js_event,
           js_event_type,
           js_flag50,
           js_cmd50,
           js_type,
           //js_skill_type,    //技能类别，包括：普通、天赋、团队天赋、状态、团队状态、装备技、称号特效。状态和团队状态是指有回合数的技能，装备技包括内功和轻功。默认为普通
           //js_harmless,      //有利时为益，有害为害，否则留空，仅对团队状态和团队天赋有效。显示buff时用不同的颜色区分有利不利。
           js_readonly, 
           hidden
        }

    public struct JsPos
    {
        public ushort scene;
        public ushort x;
        public ushort y;

        public JsPos(ushort scene,ushort x,ushort y)
        {
            this.scene = scene;
            this.x = x;
            this.y = y;
        }

        public static JsPos Zero = new JsPos(0, 0, 0);
    }

      public class  JsListItem
      {
          public string name;
          public ushort value;

          public JsListItem(string name,ushort value)
          {
              this.name = name;
              this.value = value;
          }

          public override string ToString()
          {
              return value.ToString()+" "+name;
          }
      }

        public class JsVar
        {
            public const int FlagNone = 0;
            public const int FlagAllowNoChange = 0x0100;  //意味着可以取值0xfffe
            public const int FlagEvent50_Mask = 0xff;
            public const int FlagEvent50_Bit0 = 0x01;
            public const int FlagEvent50_Bit1 = 0x02;
            public const int FlagEvent50_Bit2 = 0x04;
            public const int FlagEvent50_Bit3 = 0x08;
            public const int FlagEvent50_Bit4 = 0x10;
            public const int FlagEvent50_Bit5 = 0x20;
            public const int FlagEvent50_Bit6 = 0x40;
            public const int FlagEvent50_Bit7 = 0x80;


            public JsVarType type;
            public JsListItem[] fields;
            public string desc;
            public int min,max;   //当type=js_pos时，min表示y坐标位置偏移，max表示场景代号所在values的索引
                                  //当type=js_var50是, min表示表示flag变量在values中的索引,max表示flag变量的哪一位代表变量（0-代表最低位，1代表最高位）
            public int flag;

            public JsVar(JsVarType type, string desc=null, int min=0, int max=65535,int flag=0)
            {
                if(type==JsVarType.int16)
                {
                    if(max>Int16.MaxValue)
                    {
                        max=Int16.MaxValue;
                        min=Int16.MinValue;
                    }
                }
                this.type=type;
                this.desc=desc;
                this.min = min;
                this.max = max;
                fields = null;
                this.flag = flag;
            }

            public JsVar()
            {
                this.type = JsVarType.uint16;
                this.desc = "16位无符号数";
                this.min = 0;
                this.max = 0xffff;
                fields = null;
                this.flag = 0;
            }

            public JsVar(string desc, JsListItem[] value_fields, int flag = 0)
            {
                type = JsVarType.js_list;
                this.desc = desc;
                fields=value_fields;
                this.flag = flag;
            }

            public JsVar(JsVarType type, string desc, JsListItem[] value_fields, int flag = 0)
            {
                this.type = type;
                this.desc = desc;
                fields = value_fields;
                this.flag = flag;
            }

            public static JsListItem[] SexList = new JsListItem[] {
                new JsListItem("男",0),
                new JsListItem("女",1),
                new JsListItem("人妖",2)
            };

            public static JsListItem[] SexCmpList = new JsListItem[] {
                new JsListItem("男",0),
                new JsListItem("女",1),
                new JsListItem("人妖",2),
                new JsListItem("内部判断变量",256)
            };

            public static JsListItem[] BoolList = new JsListItem[] {
                new JsListItem("否",0),
                new JsListItem("是",1),
                new JsListItem("不改变",0xfffe)
            };

            public static JsListItem[] NeiliTypeList = new JsListItem[] {
                new JsListItem("阴性",0),
                new JsListItem("阳性",1),
                new JsListItem("阴阳调和",2)
            };

            public static JsListItem[] AttackTypeList = new JsListItem[] {
                new JsListItem("无",0),
                new JsListItem("左右互博",1),
                new JsListItem("两次攻击",2)
            };

            public static JsListItem[] ValueLengthList = new JsListItem[] {
                new JsListItem("字",0),
                new JsListItem("字节",1)
            };

            public static JsListItem[] OperTypeList = new JsListItem[] {
                new JsListItem("+",0),
                new JsListItem("-",1),
                new JsListItem("*",2),
                new JsListItem("/",3),
                new JsListItem("mod",4)
            };

            public static JsListItem[] CompareTypeList = new JsListItem[] {
                new JsListItem("≥",0),
                new JsListItem("＜",1),
                new JsListItem("=",2),
                new JsListItem("≤",3),
                new JsListItem("强制否",4),
                new JsListItem("强制是",5)
            };

            public static JsListItem[] SkillTypeList = new JsListItem[] {
                new JsListItem("暗器",0),
                new JsListItem("拳掌",1),
                new JsListItem("剑法",2),
                new JsListItem("兵器",3),
                new JsListItem("未知",4),
                new JsListItem("内功",5),
                new JsListItem("轻功",6),
                new JsListItem("天赋",7),
                new JsListItem("特技",8)
            };

            public static JsListItem[] SkillEffectList = new JsListItem[] {
                new JsListItem("减少生命",0),
                new JsListItem("减少内力",1),
                new JsListItem("恢复生命",2),
                new JsListItem("恢复内力",3)
            };

            public static JsListItem[] SkillShapeList = new JsListItem[] {
                new JsListItem("点",0),
                new JsListItem("线",1),
                new JsListItem("十字",2),
                new JsListItem("面",3),
                new JsListItem("菱形",4),
                new JsListItem("全屏",5),
                new JsListItem("自身",6),
                new JsListItem("田字",7),
                new JsListItem("井字",8),
                new JsListItem("米字",9),
                new JsListItem("楔形",10),
                new JsListItem("角形",11),
                new JsListItem("卍字",12)
            };

            public static JsListItem[] SkillRemoveStatusList = new JsListItem[] {
                new JsListItem("空",0),
                new JsListItem("解除内伤",1),
                new JsListItem("解除虚弱",2),
                new JsListItem("解除盲目",3),
                new JsListItem("解除外伤",4),
                new JsListItem("解除剧毒",5),
                new JsListItem("解除厌食",6),
                new JsListItem("解除定身",7),
                new JsListItem("解除点穴",8),
                new JsListItem("解除封气",9),
                new JsListItem("解除冰封",10),
                new JsListItem("解除封招",11)
            };

            public static JsListItem[] SkillAddStatusList = new JsListItem[] {
                new JsListItem("空",0),
                new JsListItem("重伤",65535),
                new JsListItem("虚弱",65534),
                new JsListItem("盲目",65533),
                new JsListItem("内伤",65532),
                new JsListItem("剧毒",65531),
                new JsListItem("厌食",65530),
                new JsListItem("定身",65529),
                new JsListItem("点穴",65528),
                new JsListItem("封气",65527),
                new JsListItem("冰封",65526),
                new JsListItem("封招",65525),
                new JsListItem("随机",65436)
            };

            public static JsListItem[] ObjTypeList = new JsListItem[] {
                new JsListItem("人物",0),
                new JsListItem("物品",1),
                new JsListItem("场景",2),
                new JsListItem("武功",3),
                new JsListItem("商店",4)
            };


            public static JsListItem[] PlayerDirList = new JsListItem[] {
                new JsListItem("左上",0),
                new JsListItem("右上",1),
                new JsListItem("左下",2),
                new JsListItem("右下",3)
            };

            public static JsListItem[] ObjDefautMax = new JsListItem[] {
                new JsListItem("空",0xffff)
            };

            public static JsListItem[] ObjDefautZero = new JsListItem[] {
                new JsListItem("空",0)
            };

            public static JsListItem[] ObjAllowNoChange = new JsListItem[] {
                new JsListItem("空",0),
                new JsListItem("不改变",0xfffe)
            };


        }

        public class JsPic
        {
            public ushort idx;
            public Vector2 size;
            public Vector2 offset;
            public Texture2D texture;
        }

        public class JsObj
        {
            public int idx;
            public ushort[] values;

            static byte[] buf = new byte[256];

            public void SetString(string name, int idx, int len)
            {
                int l = System.Text.Encoding.Default.GetBytes(name, 0, name.Length, buf, 0);
                int j = 0;
                for(int i = 0;i < l&& j<len;i += 2)
                {
                    if (i + 1 <l)
                        values[idx + j] = (ushort)((buf[i+1] << 8) + buf[i]);
                    else
                        values[idx + j] = buf[i];
                    j++;
                }
                while (j < len)
                    values[idx + j++] = 0;
            }

            public void CloneFrom(JsObj obj)
            {
                Array.Copy(obj.values, this.values, this.values.Length);
            }

            public void CloneTo(JsObj obj)
            {
                Array.Copy(this.values, obj.values, this.values.Length);
            }

            public string GetString(int idx, int len)
            {
                int j = 0;
                for (int i = 0; i < len; i++)
                {
                    ushort v = values[idx + i];
                    if (v > 0)
                    {
                        buf[j++] = (byte)(v & 0xff);
                        buf[j++] = (byte)(v >> 8);
                    }
                }
                return System.Text.Encoding.Default.GetString(buf,0,j);
            }

            public Point GetPos(int idx,int offset=1)
            {
                return new Point(values[idx], values[idx  + offset]);
            }

            public void SetPos(int idx, int x, int y,int offset=1)
            {
                values[idx] = (ushort)x;
                values[idx +  offset] = (ushort)y;
            }

            public void SetPos(int idx, Point pos, int offset = 1)
            {
                values[idx] = (ushort)pos.X;
                values[idx + offset] = (ushort)pos.Y;
            }

            public JsPos GetJsPos(int idx, int y_offset = 1)
            {
                return new JsPos(0, values[idx], values[idx + y_offset]);
            }

            public JsPos GetJsPos(int idx, int y_offset, int scene_index)
            {
                if (scene_index >= 0 && scene_index<values.Length)
                    return new JsPos(values[scene_index], values[idx], values[idx + y_offset]);
                return new JsPos(65535, values[idx], values[idx + y_offset]);
            }

            public JsPos GetJsPos(int idx, JsVar t)
            {
                if (t.max >= 0 && t.max < values.Length)
                    return new JsPos(values[t.max], values[idx], values[idx + t.min]);
                return new JsPos(65535, values[idx], values[idx + t.min]);
            }

            public void SetJsPos(int idx, JsPos pos, int offset = 1,int scene_index=65535)
            {
                values[idx] = pos.x;
                values[idx + offset] = pos.y;
                if(scene_index>=0&&scene_index<values.Length)
                    values[scene_index] = pos.scene;
            }

            public void SetJsPos(int idx, JsPos pos, JsVar t)
            {
                values[idx] = pos.x;
                values[idx + t.min] = pos.y;
                if(t.max>=0&&t.max<values.Length)
                    values[t.max] = pos.scene;
            }

            public bool HasEvent50Flag(int flag_index,int flag)
            {
                if(flag_index>=0&&flag_index<values.Length)
                {
                    if ((values[flag_index] & (flag & JsVar.FlagEvent50_Mask)) != 0)
                        return true;
                }
                return false;
            }

            public void Save(System.IO.BinaryWriter bw)
            {
                for (int i = 0; i < values.Length; i++)
                    bw.Write(values[i]);
            }

            public void Read(System.IO.BinaryReader br)
            {
                for (int i = 0; i < values.Length; i++)
                    values[i]=br.ReadUInt16();
            }

            public bool IsObjectRef(JsVar[] types, JsVarType t, ushort value)
            {
                if (types != null)
                {
                    int flag50_index = -1;
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (types[i].type == JsVarType.js_flag50)
                            flag50_index = i;
                        else if (types[i].type == t)
                        {
                            if (values[i] == value)
                                return true;
                        }
                        else if (types[i].type == JsVarType.js_type)
                        {
                            var tt = types[i + 1];
                            int flag_mask = tt.flag & JsVar.FlagEvent50_Mask;
                            if (flag50_index >= 0 && flag_mask != 0 && (values[flag50_index] & flag_mask) == 0)  //不含flag标志，或者flag变量不存在，或者flag标志位为0
                            {
                                if (values[i] == 0)  //npc
                                {
                                    if (t == JsVarType.js_npc && value == values[i + 1])
                                        return true;
                                }
                                else if (values[i] == 1)  //item
                                {
                                    if (t == JsVarType.js_item && value == values[i + 1])
                                        return true;
                                }
                                else if (values[i] == 2)  //scene
                                {
                                    if (t == JsVarType.js_scene && value == values[i + 1])
                                        return true;
                                }
                                else if (values[i] == 3)  //skill
                                {
                                    if (t == JsVarType.js_skill && value == values[i + 1])
                                        return true;
                                }
                            }
                        }
                    }
                }
                return false;
            }

            public bool ModifyObjectRef(JsVar[] types, JsVarType t, ushort value)
            {
                bool ret = false;
                if (types != null)
                {
                    int flag50_index = -1;
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (types[i].type == JsVarType.js_flag50)
                            flag50_index = i;
                        else if (types[i].type == t && values[i] < 0xfffe && values[i] > value)
                        {
                            values[i]--;
                            ret = true;
                        }
                        else if (types[i].type == JsVarType.js_type)
                        {
                            var tt = types[i + 1];
                            int flag_mask = tt.flag & JsVar.FlagEvent50_Mask;
                            if (flag50_index >= 0 && flag_mask != 0 && (values[flag50_index] & flag_mask) == 0)  //不含flag标志，或者flag变量不存在，或者flag标志位为0
                            {
                                if (values[i] == 0)  //npc
                                {
                                    if (t == JsVarType.js_npc && values[i + 1] < 0xfffe && value < values[i + 1])
                                    {
                                        values[i + 1]--;
                                        ret = true;
                                    }
                                }
                                else if (values[i] == 1)  //item
                                {
                                    if (t == JsVarType.js_item && values[i + 1] < 0xfffe && value < values[i + 1])
                                    {
                                        values[i + 1]--;
                                        ret = true;
                                    }
                                }
                                else if (values[i] == 2)  //scene
                                {
                                    if (t == JsVarType.js_scene && values[i + 1] < 0xfffe && value < values[i + 1])
                                    {
                                        values[i + 1]--;
                                        ret = true;
                                    }
                                }
                                else if (values[i] == 3)  //skill
                                {
                                    if (t == JsVarType.js_skill && values[i + 1] < 0xfffe && value < values[i + 1])
                                    {
                                        values[i + 1]--;
                                        ret = true;
                                    }
                                }
                            }
                        }
                    }
                }
                return ret;
            }
            
        }


        public class JsTeam : JsObj
        {
            public JsTeam()
            {
                idx = 0;
                values = new ushort[30];
            }

            public static JsVar[] types = new JsVar[]
            {
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_npc,"队友1",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友2",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友3",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友4",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友5",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友6",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友7",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友8",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友9",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友10",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友11",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友12",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友13",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友14",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友15",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友16",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友17",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友18",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友19",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友20",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_npc,"队友21",JsVar.ObjDefautMax),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden)
            };
        }

        public class JsShop : JsObj
        {
            public JsShop()
            {
                idx = 0;
                values = new ushort[15];
            }

            public override string ToString()
            {
                return "商店" + idx.ToString();
            }

            public static JsVar[] types = new JsVar[]
            {
               new JsVar(JsVarType.js_item,"物品1",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"物品2",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"物品3",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"物品4",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"物品5",JsVar.ObjDefautMax),
               new JsVar(JsVarType.uint16,"物品1数量"),
               new JsVar(JsVarType.uint16,"物品2数量"),
               new JsVar(JsVarType.uint16,"物品3数量"),
               new JsVar(JsVarType.uint16,"物品4数量"),
               new JsVar(JsVarType.uint16,"物品5数量"),
               new JsVar(JsVarType.uint16,"物品1价格"),
               new JsVar(JsVarType.uint16,"物品2价格"),
               new JsVar(JsVarType.uint16,"物品3价格"),
               new JsVar(JsVarType.uint16,"物品4价格"),
               new JsVar(JsVarType.uint16,"物品5价格")
            };
        }

        //放在resourcr\lists.z5中的suit.bin文件中
        public class JsSuit : JsObj
        {
            public JsSuit()
            {
                idx = 0;
                values = new ushort[24];
            }

            public override string ToString()
            {
                return idx.ToString("000") + " " + GetString(14,4);
            }

            public static JsVar[] types = new JsVar[]
            {
               new JsVar(JsVarType.js_item,"套装兵器"),
               new JsVar(JsVarType.js_item,"套装护甲"),
               new JsVar(JsVarType.js_item,"套装骑宠"),
               new JsVar(JsVarType.js_skill,"附加内功"),
               new JsVar(JsVarType.js_skill,"附加轻功"),
               new JsVar(JsVarType.int16,"附加攻击"),
               new JsVar(JsVarType.int16,"附加防御"),
               new JsVar(JsVarType.int16,"附加轻功"),
               new JsVar(JsVarType.int16,"附加御剑"),
               new JsVar(JsVarType.int16,"附加拳掌"),
               new JsVar(JsVarType.int16,"附加兵器"),
               new JsVar(JsVarType.int16,"附加指腿"),
               new JsVar(JsVarType.int16,"附加暗毒"),
               new JsVar(JsVarType.js_skill,"附加天赋"),
               new JsVar(JsVarType.str,"套装名称",0,4),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden)
            };
        }

        public class JsItem : JsObj
        {
            public JsItem()
            {
                idx = 0;
                values = new ushort[95]; 
            }

            public string Name
            {
                get { return GetString(0, 10); }
                set { SetString(Name, 0, 10); }
            }

            public string Desc
            {
                get { return GetString(10, 15); }
                set { SetString(Desc, 10, 15); }
            }

            public override string ToString()
            {
                return idx.ToString("0000") + " " + Name;
            }


            public static JsVar[] types = new JsVar[]
            {
               new JsVar(JsVarType.str,"名称",0,10),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.str,"说明",0,15),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_skill,"可练武功",JsVar.ObjDefautMax),
               new JsVar(JsVarType.int16,"未知2"),
               new JsVar(JsVarType.int16,"未知3"),
               new JsVar(JsVarType.int16,"未知4"),
               new JsVar(JsVarType.int16,"未知5"),
               new JsVar(JsVarType.int16,"未知6"),
               new JsVar(JsVarType.uint16,"需要家族"),
               new JsVar(JsVarType.uint16,"需要门派"),
               new JsVar(JsVarType.uint16,"未知7"),
               new JsVar(JsVarType.int16,"生命"),
               new JsVar(JsVarType.int16,"生命最大"),
               new JsVar(JsVarType.int16,"中毒"),
               new JsVar(JsVarType.int16,"体力"),
               new JsVar(JsVarType.int16,"内力性质"),
               new JsVar(JsVarType.int16,"内力"),
               new JsVar(JsVarType.int16,"内力最大"),
               new JsVar(JsVarType.int16,"攻击"),
               new JsVar(JsVarType.int16,"轻功"),
               new JsVar(JsVarType.int16,"防御"),
               new JsVar(JsVarType.int16,"医疗"),
               new JsVar(JsVarType.int16,"用毒"),
               new JsVar(JsVarType.int16,"解毒"),
               new JsVar(JsVarType.int16,"抗毒"),
               new JsVar(JsVarType.int16,"拳掌"),
               new JsVar(JsVarType.int16,"御剑"),
               new JsVar(JsVarType.int16,"兵器"),
               new JsVar(JsVarType.int16,"指腿"),
               new JsVar(JsVarType.int16,"暗毒"),
               new JsVar(JsVarType.int16,"武学常识"),
               new JsVar(JsVarType.int16,"耗费气力"),
               new JsVar(JsVarType.uint16,"左右互搏"),
               new JsVar(JsVarType.int16,"攻击带毒"),
               new JsVar(JsVarType.js_npc,"专属人物",JsVar.ObjDefautMax),
               new JsVar(JsVarType.uint16,"需要性别"),
               new JsVar(JsVarType.uint16,"需要内力性质"),
               new JsVar(JsVarType.uint16,"需要最大最大"),
               new JsVar(JsVarType.uint16,"需要攻击"),
               new JsVar(JsVarType.uint16,"需要轻功"),
               new JsVar(JsVarType.uint16,"需要用毒"),
               new JsVar(JsVarType.uint16,"需要医疗"),
               new JsVar(JsVarType.uint16,"需要解毒"),
               new JsVar(JsVarType.uint16,"需要拳掌"),
               new JsVar(JsVarType.uint16,"需要御剑"),
               new JsVar(JsVarType.uint16,"需要兵器"),
               new JsVar(JsVarType.uint16,"需要指腿"),
               new JsVar(JsVarType.uint16,"需要暗毒"),
               new JsVar(JsVarType.uint16,"需要资质"),
               new JsVar(JsVarType.uint16,"未知8"),
               new JsVar(JsVarType.uint16,"未知9"),
               new JsVar(JsVarType.uint16,"需要类型"),
               new JsVar(JsVarType.uint16,"物品1"),
               new JsVar(JsVarType.uint16,"物品2"),
               new JsVar(JsVarType.uint16,"物品3"),
               new JsVar(JsVarType.uint16,"物品4"),
               new JsVar(JsVarType.uint16,"需要数量1"),
               new JsVar(JsVarType.uint16,"需要数量2"),
               new JsVar(JsVarType.uint16,"需要数量3"),
               new JsVar(JsVarType.uint16,"需要数量4"),
               new JsVar(JsVarType.uint16,"价格"),
               new JsVar(JsVarType.uint16,"未知10"),
               new JsVar(JsVarType.uint16,"未知11"),
               new JsVar(JsVarType.uint16,"未知12"),
               new JsVar(JsVarType.uint16,"未知13"),
               new JsVar(JsVarType.uint16,"附带"),
               new JsVar(JsVarType.uint16,"未知14"),
               new JsVar(JsVarType.boolean,"可打造"),
               new JsVar(JsVarType.js_npc,"人物2",JsVar.ObjDefautMax),
               new JsVar(JsVarType.uint16,"未知15"),
               new JsVar(JsVarType.uint16,"未知16"),
               new JsVar(JsVarType.uint16,"未知17")
            };
        }

        public class JsNPC : JsObj
        {

            public JsNPC()
            {
                idx = 0;
                values = new ushort[161];
            }


            public string Name
            {
                get {
                        return GetString(4, 5);
                }
                set { SetString(Name, 4, 5); }
            }

            public string CallName
            {
                get { return GetString(9, 5); }
                set { SetString(CallName, 9, 5); }
            }

            public override string ToString()
            {
                return idx.ToString("0000") + " " + Name;
            }

            public static JsVar[] types = new JsVar[161]
            {
               new JsVar(JsVarType.uint16,"头像"),
               new JsVar(JsVarType.uint16,"出战"),
               new JsVar(JsVarType.uint16,"撤退"),
               new JsVar(JsVarType.uint16,"击杀"),
               new JsVar(JsVarType.str,"姓名",0,5),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.str,"称号",0,5),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_list,"性别",JsVar.SexList),
               new JsVar(JsVarType.uint16,"等级"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"生命"),
               new JsVar(JsVarType.uint16,"最大生命"),
               new JsVar(JsVarType.uint16,"受伤"),
               new JsVar(JsVarType.uint16,"中毒"),
               new JsVar(JsVarType.uint16,"体力"),
               new JsVar(JsVarType.uint16,"称号"),
               new JsVar(JsVarType.js_item,"武器",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"防具",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"骑宠",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_skill,"当前内功",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_skill,"当前轻功",JsVar.ObjDefautMax),
               new JsVar(JsVarType.uint16,"家族"),
               new JsVar(JsVarType.uint16,"门派"),
               new JsVar(JsVarType.uint16,"根骨"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.js_skill,"天赋武功",JsVar.ObjDefautZero),
               new JsVar(JsVarType.boolean,"是否隐藏"),
               new JsVar(JsVarType.js_skill,"专精",JsVar.ObjDefautZero),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"声音"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar("内力阴阳",JsVar.NeiliTypeList),
               new JsVar(JsVarType.uint16,"内力"),
               new JsVar(JsVarType.uint16,"最大内力"),
               new JsVar(JsVarType.uint16,"攻击"),
               new JsVar(JsVarType.uint16,"轻功"),
               new JsVar(JsVarType.uint16,"防御"),
               new JsVar(JsVarType.uint16,"医疗"),
               new JsVar(JsVarType.uint16,"用毒"),
               new JsVar(JsVarType.uint16,"解毒"),
               new JsVar(JsVarType.uint16,"抗毒"),
               new JsVar(JsVarType.uint16,"拳掌"),
               new JsVar(JsVarType.uint16,"御剑"),
               new JsVar(JsVarType.uint16,"兵器"),
               new JsVar(JsVarType.uint16,"指腿"),
               new JsVar(JsVarType.uint16,"暗毒"),
               new JsVar(JsVarType.uint16,"武学常识"),
               new JsVar(JsVarType.uint16,"人品"),
               new JsVar(JsVarType.uint16,"攻击带毒"),
               new JsVar("左右互博",JsVar.AttackTypeList),
               new JsVar(JsVarType.uint16,"体质"),
               new JsVar(JsVarType.uint16,"资质"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.js_skill,"武功1",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功2",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功3",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功4",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功5",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功6",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功7",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功8",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功9",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功10",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功11",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功12",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功13",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功14",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功15",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功16",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功17",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功18",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功19",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功20",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功21",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功22",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功23",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功24",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功25",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功26",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功27",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功28",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功29",JsVar.ObjDefautZero),
               new JsVar(JsVarType.js_skill,"武功30",JsVar.ObjDefautZero),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"未知经验1",0,65535),
               new JsVar(JsVarType.uint16,"未知经验2",0,65535),
               new JsVar(JsVarType.uint16,"未知经验3",0,65535),
               new JsVar(JsVarType.uint16,"未知经验4",0,65535),
               new JsVar(JsVarType.uint16,"未知经验5",0,65535),
               new JsVar(JsVarType.uint16,"未知经验6",0,65535),
               new JsVar(JsVarType.uint16,"未知经验7",0,65535),
               new JsVar(JsVarType.uint16,"未知经验8",0,65535),
               new JsVar(JsVarType.uint16,"武功1经验",0,65535),
               new JsVar(JsVarType.uint16,"武功2经验",0,65535),
               new JsVar(JsVarType.uint16,"武功3经验",0,65535),
               new JsVar(JsVarType.uint16,"武功4经验",0,65535),
               new JsVar(JsVarType.uint16,"武功5经验",0,65535),
               new JsVar(JsVarType.uint16,"武功6经验",0,65535),
               new JsVar(JsVarType.uint16,"武功7经验",0,65535),
               new JsVar(JsVarType.uint16,"武功8经验",0,65535),
               new JsVar(JsVarType.uint16,"武功9经验",0,65535),
               new JsVar(JsVarType.uint16,"武功10经验",0,65535),
               new JsVar(JsVarType.uint16,"武功11经验",0,65535),
               new JsVar(JsVarType.uint16,"武功12经验",0,65535),
               new JsVar(JsVarType.uint16,"武功13经验",0,65535),
               new JsVar(JsVarType.uint16,"武功14经验",0,65535),
               new JsVar(JsVarType.uint16,"武功15经验",0,65535),
               new JsVar(JsVarType.uint16,"武功16经验",0,65535),
               new JsVar(JsVarType.uint16,"武功17经验",0,65535),
               new JsVar(JsVarType.uint16,"武功18经验",0,65535),
               new JsVar(JsVarType.uint16,"武功19经验",0,65535),
               new JsVar(JsVarType.uint16,"武功20经验",0,65535),
               new JsVar(JsVarType.uint16,"武功29经验",0,65535),
               new JsVar(JsVarType.uint16,"武功30经验",0,65535),
               new JsVar(JsVarType.uint16,"1"),
               new JsVar(JsVarType.uint16,"2"),
               new JsVar(JsVarType.uint16,"3"),
               new JsVar(JsVarType.uint16,"4"),
               new JsVar(JsVarType.uint16,"5"),
               new JsVar(JsVarType.uint16,"6"),
               new JsVar(JsVarType.uint16,"7"),
               new JsVar(JsVarType.uint16,"8"),
               new JsVar(JsVarType.uint16,"9"),
               new JsVar(JsVarType.uint16,"10"),
               new JsVar(JsVarType.uint16,"11"),
               new JsVar(JsVarType.uint16,"12"),
               new JsVar(JsVarType.uint16,"13"),
               new JsVar(JsVarType.uint16,"14"),
               new JsVar(JsVarType.uint16,"15"),
               new JsVar(JsVarType.uint16,"16"),
               new JsVar(JsVarType.uint16,"17"),
               new JsVar(JsVarType.uint16,"18"),
               new JsVar(JsVarType.js_item,"携带物品1",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"携带物品2",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"携带物品3",JsVar.ObjDefautMax),
               new JsVar(JsVarType.js_item,"携带物品4",JsVar.ObjDefautMax),
               new JsVar(JsVarType.uint16,"物品数量1"),
               new JsVar(JsVarType.uint16,"物品数量2"),
               new JsVar(JsVarType.uint16,"物品数量3"),
               new JsVar(JsVarType.uint16,"物品数量4"),
               new JsVar(JsVarType.uint16,"19"),
               new JsVar(JsVarType.uint16,"20"),
               new JsVar(JsVarType.uint16,"21"),
               new JsVar(JsVarType.uint16,"22"),
               new JsVar(JsVarType.uint16,"23"),
               new JsVar(JsVarType.uint16,"24"),
               new JsVar(JsVarType.uint16,"25"),
               new JsVar(JsVarType.uint16,"26"),
               new JsVar(JsVarType.uint16,"27"),
               new JsVar(JsVarType.uint16,"28")
            };
        }

        public class JsSkill : JsObj
        {
            public JsSkill()
            {
                idx = 0;
                values = new ushort[88];
            }

            public string Name
            {
                get { return GetString(0, 5); }
                set { SetString(Name, 0, 5); }
            }

            public override string ToString()
            {
                return idx.ToString("0000") + " " + Name;
            }


            public static JsVar[] types = new JsVar[]
            {
               new JsVar(JsVarType.str,"名称",0,5),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.uint16,"命中率"),
               new JsVar(JsVarType.uint16,"自伤比例"),
               new JsVar(JsVarType.uint16,"杀体力"),
               new JsVar(JsVarType.uint16,"杀生命上限"),
               new JsVar(JsVarType.js_talk,"描述"),
               new JsVar(JsVarType.uint16,"耗气"),
               new JsVar(JsVarType.js_talk,"装备效果"),
               new JsVar(JsVarType.js_talk,"使用效果"),
               new JsVar(JsVarType.js_list,"造成异常",JsVar.SkillAddStatusList),
               new JsVar(JsVarType.int16,"造成几率"),
               new JsVar(JsVarType.int16,"回合"),
               new JsVar(JsVarType.int16,"武器"),
               new JsVar(JsVarType.int16,"暴击率"),
               new JsVar(JsVarType.int16,"双击率"),
               new JsVar(JsVarType.js_skill,"被触发武功",JsVar.ObjDefautZero),
               new JsVar(JsVarType.int16,"被触发几率"),
               new JsVar(JsVarType.int16,"攻击"),
               new JsVar(JsVarType.int16,"轻功"),
               new JsVar(JsVarType.int16,"等级"),
               new JsVar(JsVarType.int16,"拳掌"),
               new JsVar(JsVarType.int16,"御剑"),
               new JsVar(JsVarType.int16,"兵器"),
               new JsVar(JsVarType.int16,"指腿"),
               new JsVar(JsVarType.int16,"暗毒"),
               new JsVar(JsVarType.int16,"内功"),
               new JsVar(JsVarType.uint16,"未知"),
               new JsVar(JsVarType.uint16,"声音"),
               new JsVar(JsVarType.js_list,"武功类型",JsVar.SkillTypeList),
               new JsVar(JsVarType.uint16,"动画"),
               new JsVar(JsVarType.js_list,"武功效果",JsVar.SkillEffectList),
               new JsVar(JsVarType.js_list,"攻击形状",JsVar.SkillShapeList),
               new JsVar(JsVarType.int16,"耗内力"),
               new JsVar(JsVarType.int16,"中毒"),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,"威力"),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,"移动"),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,"范围"),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,""),
               new JsVar(JsVarType.uint16,"")
            };
        }
   
        public class JsEventType
        {
            public ushort cmd;
            public ushort len;
            public string desc;
            public JsVar[] types;


            public JsEventType(ushort c, ushort l, string d=null, JsVar[] types=null)
            {
                cmd=c;len=l;desc=d;
                this.types = types;
            }

            public override string ToString()
            {
                return cmd.ToString("(00000)") + desc;
            }


            public static JsEventType[] EventTypeList = new JsEventType[]
            {
	              new JsEventType( 0,  0, "清屏"),
	              new JsEventType( 1,  3, "对话" ,new JsVar[]{
                      new JsVar(JsVarType.js_talk,"对话",0),
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.js_readonly,"对话框位置")
                  }),
	              new JsEventType( 2,  2, "得到物品",new JsVar[]{
                      new JsVar(JsVarType.js_item,"物品"),
                      new JsVar(JsVarType.int16,"数量",short.MinValue,short.MaxValue)
                  }),
	              new JsEventType( 3,  13,"修改场景事件",new JsVar[]{
                      new JsVar(JsVarType.js_scene,"场景", JsVar.ObjAllowNoChange),
                      new JsVar(JsVarType.uint16,"场景事件", 0, 199, JsVar.FlagAllowNoChange),
                      new JsVar("阻止移动",JsVar.BoolList),
                      new JsVar(JsVarType.js_readonly,"序号"),
                      new JsVar(JsVarType.js_event,"调查触发事件", JsVar.ObjAllowNoChange),
                      new JsVar(JsVarType.js_event,"物品触发事件",  JsVar.ObjAllowNoChange),
                      new JsVar(JsVarType.js_event,"走过触发事件",  JsVar.ObjAllowNoChange),
                      new JsVar(JsVarType.js_pic,"事件点图片", 0,65535, JsVar.FlagAllowNoChange),
                      new JsVar(JsVarType.js_pic,"事件点图片2", 0,65535, JsVar.FlagAllowNoChange),
                      new JsVar(JsVarType.js_pic,"事件点图片3", 0,65535, JsVar.FlagAllowNoChange),
                      new JsVar(JsVarType.uint16,"动画速度", 0,65535, JsVar.FlagAllowNoChange),
                      new JsVar(JsVarType.js_pos,"坐标",1,0, JsVar.FlagAllowNoChange),
                      new JsVar(JsVarType.hidden)

                  }),
	              new JsEventType( 4,  3, "物品触发事件",new JsVar[]{
                      new JsVar(JsVarType.js_item,"物品"),
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 5,  2, "是否战斗",new JsVar[]{
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 6,  4, "战斗",new JsVar[]{
                      new JsVar(JsVarType.uint16,"战斗场景"),
                      new JsVar(JsVarType.uint16,"胜偏移"),
                      new JsVar(JsVarType.uint16,"输偏移"),
                      new JsVar(JsVarType.uint16,"输是否有经验")
                  }),
	              new JsEventType( 7,  0, "事件强制结束" ),
	              new JsEventType( 8,  1, "改变音乐",new JsVar[]{
                      new JsVar(JsVarType.uint16,"音乐编号")
                  }),
	              new JsEventType( 9,  2, "询问是否加入",new JsVar[]{
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 10, 1, "加入队员 ",new JsVar[]{
                      new JsVar(JsVarType.js_npc,"队员")
                  }),
	              new JsEventType( 11, 2, "是否住宿 ",new JsVar[]{
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 12, 0, "住宿" ),
	              new JsEventType( 13, 0, "场景重新显示" ),
	              new JsEventType( 14, 0, "场景淡出" ),
	              new JsEventType( 15, 1, "死亡回到选单",new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1")
                  }),
	              new JsEventType( 16, 3, "是否有队友",new JsVar[]{
                      new JsVar(JsVarType.js_npc,"队友"),
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 17, 5, "修改场景图片" ,new JsVar[]{
                      new JsVar(JsVarType.js_npc,"场景"),
                      new JsVar(JsVarType.uint16,"图层"),
                      new JsVar(JsVarType.js_pos,"坐标",1,0), 
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.js_pic,"图片")
                  }),
	              new JsEventType( 18, 3, "是否有物品" ,new JsVar[]{
                      new JsVar(JsVarType.js_item,"物品"),
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 19, 2, "改变主角位置" ,new JsVar[]{
                      new JsVar(JsVarType.js_pos,"位置",1),
                      new JsVar(JsVarType.hidden)
                  }),
	              new JsEventType( 20, 2, "是否队伍满 ",new JsVar[]{
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 21, 1, "队员离队 " ,new JsVar[]{
                      new JsVar(JsVarType.js_npc,"队员")
                  }),
	              new JsEventType( 22, 0, "内力降为0 " ),
	              new JsEventType( 23, 2, "用毒能力" ,new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 24, 0, "死亡黑屏" ),
	              new JsEventType( 25, 4, "场景移动 ",new JsVar[]{
                      new JsVar(JsVarType.js_pos,"起始坐标",1),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.js_pos,"结束坐标",1),
                      new JsVar(JsVarType.hidden)
                  }),
	              new JsEventType( 26, 5, "场景增加事件", new JsVar[]{
                      new JsVar(JsVarType.js_scene,"场景"),
                      new JsVar(JsVarType.uint16,"事件编号",0,199),
                      new JsVar(JsVarType.js_event,"调查事件"),
                      new JsVar(JsVarType.js_event,"道具事件"),
                      new JsVar(JsVarType.js_event,"走过事件")
                  }),
	              new JsEventType( 27, 3, "显示动画", new JsVar[]{
                      new JsVar(JsVarType.js_pic,"图片1"),
                      new JsVar(JsVarType.js_pic,"图片2"),
                      new JsVar(JsVarType.js_pic,"图片3")
                  }),
	              new JsEventType( 28, 5, "判断品德", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.uint16,"数值下限"),
                      new JsVar(JsVarType.uint16,"数值上限"),
                      new JsVar(JsVarType.uint16,"是偏移量"),
                      new JsVar(JsVarType.uint16,"是偏移量")
                  }),
	              new JsEventType( 29, 5, "判断武力", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.uint16,"数值下限"),
                      new JsVar(JsVarType.uint16,"数值上限"),
                      new JsVar(JsVarType.uint16,"是偏移量"),
                      new JsVar(JsVarType.uint16,"是偏移量")
                  }),
	              new JsEventType( 30, 4, "主角走动",new JsVar[]{
                      new JsVar(JsVarType.js_pos,"起始位置",1),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.js_pos,"结束位置",1),
                      new JsVar(JsVarType.hidden)
                  }),
	              new JsEventType( 31, 3, "判断银子" ,new JsVar[]{ 
                      new JsVar(JsVarType.uint16,"数量下限"),
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 32, 2, "增加物品 ", new JsVar[]{
                      new JsVar(JsVarType.js_item,"物品"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 33, 1, "学会武功" ,new JsVar[]{   //有可能只有一个参数
                      new JsVar(JsVarType.js_skill,"武功")
                  }),
	              new JsEventType( 34, 2, "增加资质", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 35, 4, "设置武功",new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.uint16,"武功栏位",0,29),
                      new JsVar(JsVarType.js_skill,"武功"),
                      new JsVar(JsVarType.uint16,"经验")
                  }),
	              new JsEventType( 36, 3, "判断主角性别", new JsVar[]{
                      new JsVar("性别",JsVar.SexCmpList),
                      new JsVar(JsVarType.uint16,"是偏移量"),
                      new JsVar(JsVarType.uint16,"是偏移量")
                  }),
	              new JsEventType( 37, 1, "增加品德", new JsVar[]{
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 38, 4, "修改场景贴图", new JsVar[]{
                      new JsVar(JsVarType.js_scene,"场景"),
                      new JsVar(JsVarType.uint16,"图层"),
                      new JsVar(JsVarType.js_pic,"原有贴图"),
                      new JsVar(JsVarType.js_pic,"新的贴图")
                  }),
	              new JsEventType( 39, 1, "打开场景", new JsVar[]{
                      new JsVar(JsVarType.js_scene,"场景")
                  }),
	              new JsEventType( 40, 1, "主角面向 ", new JsVar[]{
                      new JsVar(JsVarType.js_list,"面向",JsVar.PlayerDirList)
                  }),
	              new JsEventType( 41, 3, "他人增加物品 ", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.js_item,"人物"),
                       new JsVar(JsVarType.int16,"数量")
                  }),
	              new JsEventType( 42, 2, "是否有女队友", new JsVar[]{
                      new JsVar(JsVarType.uint16,"是偏移量"),
                      new JsVar(JsVarType.uint16,"是偏移量")
                  }),
	              new JsEventType( 43, 3, "是否有物品", new JsVar[]{
                      new JsVar(JsVarType.js_item,"物品"),
                      new JsVar(JsVarType.uint16,"是偏移量"),
                      new JsVar(JsVarType.uint16,"是偏移量")
                  }),
	              new JsEventType( 44, 6, "播放动画", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4"),
                      new JsVar(JsVarType.uint16,"参数5"),
                      new JsVar(JsVarType.uint16,"参数6")
                  }),
	              new JsEventType( 45, 2, "增加轻功", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 46, 2, "增加内力", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 47, 2, "增加武力", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 48, 2, "增加生命", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 49, 2, "设置内力", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 50, 7, "50指令", new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4"),
                      new JsVar(JsVarType.uint16,"参数5"),
                      new JsVar(JsVarType.uint16,"参数6"),
                      new JsVar(JsVarType.uint16,"参数7")
                  }),
	              new JsEventType( 51, 0, "问软体娃娃"),
	              new JsEventType( 52, 0, "看道德"),
	              new JsEventType( 53, 0, "看声望"),
	              new JsEventType( 54, 0, "见过南贤" ),
	              new JsEventType( 55, 4, "是否事件" , new JsVar[]{
                      new JsVar(JsVarType.uint16,"事件"),
                      new JsVar(JsVarType.uint16,"给定编号"),
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 56, 1, "增加声望",new JsVar[]{
                      new JsVar(JsVarType.int16,"数值")
                  }),
	              new JsEventType( 57, 0, "高昌迷宫动画" ),
	              new JsEventType( 58, 0, "武道大会比武" ),
	              new JsEventType( 59, 0, "失去所有队员" ),
	              new JsEventType( 60, 5, "判断场景图块", new JsVar[]{
                      new JsVar(JsVarType.js_pos,"位置",1),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.js_pic,"图层"),                      
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 61, 2, "14天数放完", new JsVar[]{
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
	              new JsEventType( 62, 6, "时空机动画"),
	              new JsEventType( 63, 2, "设置性别", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.uint16,"性别")
                  }),
	              new JsEventType( 64, 0, "韦小宝卖东西 " ),
	              new JsEventType( 65, 0, "韦小宝离开" ),
	              new JsEventType( 66, 1, "播放音乐 ", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1")
                  }),
	              new JsEventType( 67, 1, "播放声音", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1")
                  }),
	              new JsEventType( 68, 0, "未知" ),
	              new JsEventType( 69, 2, "对话替换字符", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2")
                  }),
	              new JsEventType( 70, 0, "未知70" ),
	              new JsEventType( 71, 0, "场景移动"
                      //, new JsVar[]{    //0个参数
                      //new JsVar(JsVarType.js_scene,"场景"),
                      //new JsVar(JsVarType.js_pos,"位置",1,0),
                      //new JsVar(JsVarType.hidden) }
                  ),
	              new JsEventType( 72, 3, "判断物品存在", new JsVar[]{
                      new JsVar(JsVarType.js_item,"物品"),
                      new JsVar(JsVarType.uint16,"是偏移"),
                      new JsVar(JsVarType.uint16,"否偏移")
                  }),
                  new JsEventType( 74, 1, "未知74", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1")
                  }),
                   new JsEventType( 75, 3, "未知75", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3")
                  }),
                  new JsEventType( 76, 1, "未知76", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1")
                  }),
                  new JsEventType( 77, 1, "增加任务", new JsVar[]{
                      new JsVar(JsVarType.js_task,"任务描述")
                  }),
                  new JsEventType( 78, 1, "完成任务", new JsVar[]{
                      new JsVar(JsVarType.js_task,"任务描述")
                  }),
                  new JsEventType( 79, 2, "79增加属性", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
                  new JsEventType( 80, 3, "80增加属性", new JsVar[]{
                      new JsVar(JsVarType.js_npc,"人物"),
                      new JsVar(JsVarType.int16,"属性偏移"),
                      new JsVar(JsVarType.int16,"数值")
                  }),
                   new JsEventType( 81, 3, "未知81", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3")
                  }),
                   new JsEventType( 82, 3, "未知82", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3")
                  }),
                   new JsEventType( 83, 4, "未知83", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4")
                  }),
                  new JsEventType( 84, 0, "未知84" ),
                  new JsEventType( 85, 14, "未知85", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4"),
                      new JsVar(JsVarType.uint16,"参数5"),
                      new JsVar(JsVarType.uint16,"参数6"),
                      new JsVar(JsVarType.uint16,"参数7"),
                      new JsVar(JsVarType.uint16,"参数8"),
                      new JsVar(JsVarType.uint16,"参数9"),
                      new JsVar(JsVarType.uint16,"参数10"),
                      new JsVar(JsVarType.uint16,"参数11"),
                      new JsVar(JsVarType.uint16,"参数12"),
                      new JsVar(JsVarType.uint16,"参数13"),
                      new JsVar(JsVarType.uint16,"参数14")
                  }),
                   new JsEventType( 86, 4, "未知86", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4")
                  }),
                  new JsEventType( 87, 2, "未知87", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2")
                  }),
                  new JsEventType( 88, 0, "未知88" ),
                   new JsEventType( 89, 2, "未知89", new JsVar[]{
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2")
                  }),
	              new JsEventType( 0xffff, 0, "事件结束")
            };

            //50指令描述
            public static JsEventType[] Event50TypeList = new JsEventType[]
            {
	              new JsEventType( 0,  7, "给变量赋值",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.uint16,"变量号"),
                      new JsVar(JsVarType.uint16,"值"),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
	              new JsEventType( 1,  7, "给数组赋值",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar("长度",JsVar.ValueLengthList),
                      new JsVar(JsVarType.uint16,"数组号"),
                      new JsVar(JsVarType.uint16,"数组索引", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"要赋予的值", 1,1),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 2,  7, "从数组取值",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar("长度",JsVar.ValueLengthList),
                      new JsVar(JsVarType.uint16,"变量序号"),
                      new JsVar(JsVarType.uint16,"数组索引", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"数组序号"),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 3,  7, "y= a op b",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar("op",JsVar.OperTypeList),
                      new JsVar(JsVarType.uint16,"y"),
                      new JsVar(JsVarType.uint16,"a"),
                      new JsVar(JsVarType.uint16,"b", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 4,  7, "变量判断",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.hidden),
                      new JsVar("a比较b",JsVar.CompareTypeList),
                      new JsVar(JsVarType.uint16,"a"),
                      new JsVar(JsVarType.uint16,"b"),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 5,  7, "全部变量清零",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
                   new JsEventType( 6,  7, "变量命名",new JsVar[]{
                       new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.uint16,"变量序号"),
                      new JsVar(JsVarType.str,"名称",0,5),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 16,  7, "设定属性",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.js_type,"设定对象",JsVar.ObjTypeList),
                      new JsVar(JsVarType.uint16,"对象序号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"属性偏移", 0,65535,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"数值", 0,65535,JsVar.FlagEvent50_Bit2),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 17,  7, "取属性",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.js_type,"操作对象",JsVar.ObjTypeList),
                      new JsVar(JsVarType.uint16,"对象序号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"属性偏移", 0,65535,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"变量序号"),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 18,  7, "设定队友",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"队伍位置", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"人物编码", 0,65535,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 19,  7, "取队友",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"队伍位置", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"变量序号"),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 20,  7, "取物品数量",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"物品编号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"变量序号"),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden),
                      new JsVar(JsVarType.hidden)
                  }),
                   new JsEventType( 21,  7, "设定场景事件",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"场景编号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"场景事件序号", 0,199,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"场景事件偏移", 0,65535,JsVar.FlagEvent50_Bit2),
                      new JsVar(JsVarType.uint16,"数值", 0,65535,JsVar.FlagEvent50_Bit3),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 22,  7, "取场景事件",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"场景编号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"场景事件序号", 0,199,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"场景事件偏移", 0,65535,JsVar.FlagEvent50_Bit2),
                      new JsVar(JsVarType.uint16,"变量序号"),
                      new JsVar(JsVarType.hidden)
                  }),
                  new JsEventType( 23,  7, "设定场景地图",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"场景编号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"层", 0,65535,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"x坐标", 0,65535,JsVar.FlagEvent50_Bit2),
                      new JsVar(JsVarType.uint16,"y坐标", 0,65535,JsVar.FlagEvent50_Bit3),
                      new JsVar(JsVarType.uint16,"数值", 0,65535,JsVar.FlagEvent50_Bit4)
                  }),
                  new JsEventType( 24,  7, "取场景地图",new JsVar[]{
                       new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"场景编号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"层", 0,65535,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"x坐标", 0,65535,JsVar.FlagEvent50_Bit2),
                      new JsVar(JsVarType.uint16,"y坐标", 0,65535,JsVar.FlagEvent50_Bit3),
                      new JsVar(JsVarType.uint16,"变量序号")
                  }),
                   new JsEventType( 43,  7, "调用其他事件 ",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.js_flag50),
                      new JsVar(JsVarType.uint16,"事件号", 0,65535,JsVar.FlagEvent50_Bit0),
                      new JsVar(JsVarType.uint16,"参数1", 0,65535,JsVar.FlagEvent50_Bit1),
                      new JsVar(JsVarType.uint16,"参数2", 0,65535,JsVar.FlagEvent50_Bit2),
                      new JsVar(JsVarType.uint16,"参数3", 0,65535,JsVar.FlagEvent50_Bit3),
                      new JsVar(JsVarType.uint16,"参数4", 0,65535,JsVar.FlagEvent50_Bit4)
                  }),
                  new JsEventType( 45,  7, "未知 ",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4"),
                      new JsVar(JsVarType.uint16,"参数5"),
                      new JsVar(JsVarType.uint16,"参数6")
                  }),
                   new JsEventType( 50,  7, "未知 ",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4"),
                      new JsVar(JsVarType.uint16,"参数5"),
                      new JsVar(JsVarType.uint16,"参数6")
                  }),
                  new JsEventType( 51,  7, "未知 ",new JsVar[]{
                      new JsVar(JsVarType.js_cmd50,"50指令"),
                      new JsVar(JsVarType.uint16,"参数1"),
                      new JsVar(JsVarType.uint16,"参数2"),
                      new JsVar(JsVarType.uint16,"参数3"),
                      new JsVar(JsVarType.uint16,"参数4"),
                      new JsVar(JsVarType.uint16,"参数5"),
                      new JsVar(JsVarType.uint16,"参数6")
                  })
            };

            public static JsEventType GetEventType(ushort cmd)
            {
                foreach (var t in EventTypeList)
                    if (t.cmd == cmd)
                        return t;
                return null;
            }

            public static JsEventType GetEvent50Type(ushort cmd)
            {
                foreach (var t in Event50TypeList)
                    if (t.cmd == cmd)
                        return t;
                return null;
            }
        }

        public class JsEventLine : JsObj
        {
            public JsEventType type;


            public JsEventLine(JsEventType type)
            {
                this.type = type;
                values=new ushort[type.len];
            }

            public override string ToString()
            {
                return idx.ToString("000") + " " + type.desc;
            }

            public bool IsObjectRef(JsVarType t, ushort value)
            {
                return IsObjectRef(type.types, t, value);
            }

            public bool ModifyObjectRef(JsVarType t, ushort value)
            {
                return ModifyObjectRef(type.types, t, value);
            }
        }

        public class JsEvent
        {
            public int idx;
            public List<JsEventLine> Lines = new List<JsEventLine>();


            public override string ToString()
            {
                return idx.ToString("0000")+" "+Lines.Count.ToString()+" lines";
            }

            public Object FindObjectRef(JsVarType t,ushort index)
            {
                foreach (var l in Lines)
                    if (l.IsObjectRef(t, index))
                        return l;
                return null;
            }

            public bool ModifyObjectRef(JsVarType t, ushort index)
            {
                bool ret = false;
                foreach (var l in Lines)
                   ret=ret||l.ModifyObjectRef(t, index);
                return ret;
            }

            public JsEventLine AddLine(JsEventType type,int index)
            {
                if (index < 0 || index > Lines.Count) 
                    index = Lines.Count;
                JsEventLine el = new JsEventLine(type);
                el.idx = index;
                Lines.Insert(index, el);
                for (int i = index+1; i < Lines.Count; i++)  //更正索引
                    Lines[i].idx = i;
                return el;
            }

            public JsEventLine ChangeType(JsEventType type, int index)
            {
                if (index >= 0 && index < Lines.Count && Lines[index].type != type)                
                {
                    JsEventLine el = new JsEventLine(type);
                    for (int i = 0; i < Lines[index].values.Length && i < el.values.Length; i++)
                        el.values[i]=Lines[index].values[i];
                    el.idx = Lines[index].idx;
                    Lines[index] = el;
                    return el;
                }
                return null;
            }

            public void RemoveLine(int index)
            {
                if (index >= 0 && index < Lines.Count)
                {
                    Lines.RemoveAt(index);
                    for(int i=index;i<Lines.Count;i++)
                        Lines[i].idx = i;
                }
            }

            public bool MoveLineFirst(int index)
            {
                if (index>0&&index<Lines.Count)
                {
                    JsEventLine el = Lines[index];
                    for (int i = index; i > 0;i--)
                    {
                        Lines[i] = Lines[i - 1];
                        Lines[i].idx=i;
                    }
                    Lines[0] = el;
                    el.idx = 0;
                    return true;
                }
                return false;
            }

            public bool MoveLineEnd(int index)
            {
                if (index >= 0 && index+1 < Lines.Count)
                {
                    JsEventLine el = Lines[index];
                    for (int i = index+1; i<Lines.Count; i++)
                    {
                        Lines[i-1] = Lines[i];
                        Lines[i-1].idx -=1;
                    }
                    Lines[Lines.Count-1] = el;
                    el.idx = Lines.Count - 1;
                    return true;
                }
                return false;
            }

            public bool MoveLineUp(int index)
            {
                if (index > 0 && index < Lines.Count)
                {
                    JsEventLine el = Lines[index];
                    Lines[index] = Lines[index - 1];
                    Lines[index].idx+=1;
                    Lines[index - 1] = el;
                    el.idx-=1;
                    return true;
                }
                return false;
            }

            public bool MoveLineDown(int index)
            {
                if (index >= 0 && index+1 < Lines.Count)
                {
                    JsEventLine el = Lines[index];
                    Lines[index] = Lines[index + 1];
                    Lines[index].idx -= 1;
                    Lines[index + 1] = el;
                    el.idx += 1;
                    return true;
                }
                return false;
            }
    
        }

        public class JsSceneEvent : JsObj
        {

            public bool IsNull()
            {
                for (int i = 0; i < values.Length; i++)
                    if (values[i] != 0)
                        return false;
                return true;
            }

            public void SetNull()
            {
                for (int i = 0; i < values.Length; i++)
                    values[i] = 0;
            }

            public JsSceneEvent()
            {
                values = new ushort[11];
            }

            public Point GetPos()
            {
                return new Point(values[9], values[10]);
            }


            public override string ToString()
            {
                if (IsNull())
                    return idx.ToString("000");
                else
                    return string.Format("{0:000} - ({1},{2})",idx,values[9],values[10]);
            }

            //public ushort can_pass;           //能否通过     0能通过；1不能通过
            //public ushort order;              //编号         在此场景中的顺序编号(0-199)？
            //public JsEvent event_action;      //主角在该触发点调查所引发的事件(FF FF 为无)
            //public JsEvent event_item;        //主角使用物品时触发(FF FF 为无)
            //public JsEvent event_move;        //主角走过时触发(FF FF 为无)
            //public JsPic pic1;                  //该事件点显示的贴图(FF FF 为无)
            //public JsPic pic2;                  //如果与贴图1不同，则为动画(FF FF 为无)
            //public JsPic pic3;                  //同上(FF FF 为无)
            //public ushort anim_speed;         //动画的速度（每秒帧数）>=0
            //public ushort x, y;               //在地图X方向上的位置，值：0-63

            public static JsVar[] types = new JsVar[11]
            {
               new JsVar(JsVarType.boolean,"阻止移动"),
               new JsVar(JsVarType.hidden,"序号"),
               new JsVar(JsVarType.js_event,"调查触发事件"),
               new JsVar(JsVarType.js_event,"物品触发事件"),
               new JsVar(JsVarType.js_event,"走过触发事件"),
               new JsVar(JsVarType.js_pic,"事件点图片"),
               new JsVar(JsVarType.js_pic,"事件点图片2"),
               new JsVar(JsVarType.js_pic,"事件点图片3"),
               new JsVar(JsVarType.uint16,"动画速度"),
               new JsVar(JsVarType.js_pos,"坐标",1),
               new JsVar(JsVarType.hidden)
            };
        }

        //public class JsSceneCell : JsObj
        //{
        //    public JsSceneCell()
        //    {
        //        idx = 0;
        //        values = new ushort[6];
        //    }

        //    public static JsVar[] types = new JsVar[6]
        //    {
        //       new JsVar(JsVarType.js_pic,"地表"),
        //       new JsVar(JsVarType.js_pic,"地物"),
        //       new JsVar(JsVarType.js_pic,"附加"),
        //       new JsVar(JsVarType.js_scene_event,"场景事件",0,199),
        //       new JsVar(JsVarType.int16,"地物层高度",short.MinValue,short.MaxValue),
        //       new JsVar(JsVarType.int16,"附加层高度",short.MinValue,short.MaxValue)
        //    };
        //}

        /*
            每个场景分6层图，每层图大小64×64。
            前三层为：每两个字节存储1个贴图代码（贴图索引号×2），若无贴图用00 00填充。 
            1层：地面贴图代码数据 
            2层：建筑贴图代码数据（如花草、房子、树木、石头），如果这个位置代码为00 00表示人可以通过。【-1也表示该位置无建筑】
            3层：空中贴图代码数据（如：挂在墙上的画、剑或摆放桌面的花瓶等挂或悬或摆在空中的事物） 
            第四层为：每两个字节在地图中相应位置（D*中相应场景事件描述的XY坐标）存储1个事件索引（D*中相应场景事件的顺序号），若无事件则用FF FF（-1）填充。
            4层：场景事件数据 
            第五、六层为：使2、3层表现为凸出或凹陷，每两个字节存储1个海拔数据，若无海拔则用00 00填充。
            5层：建筑海拔（2层y方向偏移），表示第2层图片在贴图时需要向上偏移象素数【也是人物贴图的偏移量】
            6层：空中海拔（3层y方向偏移），表示第3层图片在贴图时需要向上偏移象素数

         */
        public class JsScene : JsObj
        {
            public ushort[,,] map = new ushort[6,64,64];
            public JsSceneEvent[] events = new JsSceneEvent[200];
            public JsScene()
            {
                idx = 0;
                values=new ushort[26];
            }

            public string Name
            {
                get { return GetString(1, 5); }
                set { SetString(Name, 1, 5); }
            }

            public JsSceneEvent GetEvent(int idx)
            {
                if (idx >= 0 && idx < events.Length)
                    return events[idx];
                return null;
            }

            public JsSceneEvent GetEvent(int x,int y)
            {
                int idx = map[3, y, x];
                if (idx >= 0 && idx < events.Length)
                    return events[idx];
                return null;
            }
            

            public ushort GetMapEvent(JsSceneEvent e)
            {
                return map[3, e.values[10], e.values[9]];
            }

            public void SetMapEvent(JsSceneEvent e, ushort idx)
            {
                map[3, e.values[10], e.values[9]] = idx;
            }

            public void SetMapEvent(JsSceneEvent dest, JsSceneEvent src)
            {
                ushort e = map[3, dest.values[10], dest.values[9]];
                map[3, dest.values[10], dest.values[9]] = map[3, src.values[10], src.values[9]];
                map[3, src.values[10], src.values[9]] = e;
            }

            public void SetMapEvent(JsSceneEvent e)
            {
                map[3, e.values[10], e.values[9]] = (ushort)e.idx;
            }

            public void SetMapEvent(int x,int y,ushort idx)
            {
                map[3, y, x] = idx;
            }

            public ushort GetMapEvent(int x,int y)
            {
                return map[3, y, x];
            }

            public void SetMap(int level,int x,int y,ushort idx)
            {
                if (level >= 0 && level < 6)
                    if (x >= 0 && x < 64 && y >= 0 && y < 64)
                        map[level, y, x] = idx;
            }

            public int GetMap(int level, int x, int y)
            {
                if (level >= 0 && level < 6)
                    if (x >= 0 && x < 64 && y >= 0 && y < 64)
                        return map[level, y, x];
                return -1;
            }

            public void RemoveSceneEvent(int index)
            {
                if (index >= 0 && index < events.Length)
                {
                    events[index].SetNull();
                    if (idx == map[3, events[index].values[10], events[index].values[9]])
                        map[3, events[index].values[10], events[index].values[9]] = 0xffff;
                }
            }

            public Point GetEnter()
            {
                return GetPos(14);
            }

            public Point GetExit(int idx)
            {
                return GetPos(16+idx,3);
            }

            public Point GetSubEnter()
            {
                return GetPos(22);
            }

            public Point GetSubExit()
            {
                return GetPos(24);
            }

            public ushort GetSubSceneIdx()
            {
                return values[8];
            }


            public override string ToString()
            {
                return idx.ToString("000")+" "+Name;
            }

            public static JsVar[] types = new JsVar[26]
            {
               new JsVar(JsVarType.uint16,"序号"),
               new JsVar(JsVarType.str,"名称",0,5),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.uint16,"0xffff"),
               new JsVar(JsVarType.uint16,"1"),
               new JsVar(JsVarType.js_scene,"子场景",JsVar.ObjDefautZero),
               new JsVar(JsVarType.uint16,"0"),
               new JsVar(JsVarType.hidden,"大地图入口坐标1"),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden,"大地图入口坐标2"),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_pos,"场景入口坐标",1),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_pos,"场景出口坐标1",3),
               new JsVar(JsVarType.js_pos,"场景出口坐标2",3),
               new JsVar(JsVarType.js_pos,"场景出口坐标2",3),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_pos,"子场景入口坐标",1),
               new JsVar(JsVarType.hidden),
               new JsVar(JsVarType.js_pos,"子场景返回坐标2",1),
               new JsVar(JsVarType.hidden,"")
            };
        }

/*
r.grp结构
    short  //0
    short is_bigmap;  //1=大地图 0-场景
    short bigmap_x;  //大地图x坐标
    short bigmap_y;  //大地图y坐标
    short scene_x;  //大地图x坐标
    short scene_y;  //大地图y坐标
    short flag1;
    short flag2;
    short flag3;
    short flag4;
    short scene_id;
    byte unknow[12]
    char [12] ='nogninnur',0,0,0
    char [14]='V5.44',0,0,0,0,0,0,0,0,0
    int item_type_count;   //拥有的物品数量
    int item_types[item_type_count];  //拥有的物品序号
    int item_count_count;    //拥有的物品数量
    int item_counts[item_count_count];   //拥有的物品数量
    int npc_count;  //0x8ee
    npc npc_list[npc_count];  //每个npc 322字节
    int item_count;  //0x349
    item item_list[item_count];  //每个item 190字节
    int scene_count;   //185=0xb9
    scene scene_list[scene_count];  //每个scene 52字节
    {
        ushort idx;
        char name[10];
        ushort[20]
    }
    int skill_count;   //0x527
    skill skill_list[skill_count];  //每个skill 176字节
    int shop_count;  //商店数量  //0x0d
    shop_list[shop_count]    //390byte
    {
        short item_ids[5];         //可卖物品序号
        short item_left_count[5];  //可卖物品数量
        short item_price[5]        //可卖物品价格
    }
    int team[30]= { 0,0x3f,0x92,0x3b,0x38,0xffffffff，}; //第一是主角序号0，其他29个未知是队友编号，如果位置空则为0xffffffff
    char md5_hex_str[32];
    int week;  //1   周目
    int diffculty; //1  难度
    int fight_mode;  //2  即时制
    byte charmap[256];  //字符映射表
    int 游戏时长（秒）
    int 游戏总时常（秒）
    int 存档时间（1970年至今秒数）
    int 未知
    byte unknow[1072];

*/
    public class RGRP
    {
        public ushort h1;
        public ushort in_scene;
        public ushort bigmap_x, bigmap_y;
        public ushort scene_x, scene_y;
        public byte[] unknow0 = new byte[8];
        public short scene_id;
        public byte[] unknow1 = new byte[12];
        public byte[] nogninnur = new byte[12];
        public byte[] version = new byte[14];


        public byte[] md5 = new byte[32];
        public int week;
        public int diffculty;
        public int game_mode;
        public byte[] charmap = new byte[256];
        public uint game_time;
        public uint total_game_time;
        public uint save_time;
        public int unknow_int;
        public byte[] ender = new byte[1072];
         }

         /* talkhistory.grp格式
          * int count1;  //65
          * int[count1];
          * int count2;  //65
          * struct [count2]
          * {
          *    short[12];  // B0 5B 00 00 55 05 AF 5B 00 00 63 02
          * }
          */
          
        /* j.grp格式
         * int ;   //0
         * int ;   //1
         * int  //0xae=174
         * int task_count;  
         * short task_list[task_count];  //任务描述id（实际上就是对话的id）
         * int count2;
         * short [count2];
        */

 

}